function addTab(node){
	var flag = $('#center-tabs').tabs('getTab',node.text);
	
	var content = '<iframe src="'+node.attributes.url+'" style="'+'height:100%;width:100%;" scrolling="no"/>';
		
	if(flag==null){
		$('#center-tabs').tabs('add',{    
		    title:node.text,    
		    content:content,
		    closable:true,
//		    onLoad:function(panel){
//		    	panel.href=node.attributes.url;
//		    }
		});
	}else{
		$('#center-tabs').tabs('select',node.text);
	}
}

function newTab(text,params){
	$("#tb").datagrid({
	   	url:"href/boms",
	   	method:"get",
	   	queryParams:params,
		columns:[[    
			{field:'Id',title:'全选',width:100,checkbox:true},      
			{field:'partnum',title:'物料编号',width:100,align:'center'},    
			{field:'desc',title:'物料名称',width:100,align:'center'}, 
			{field:'size',title:'物料规格',width:100,align:'center'},
			{field:'weight',title:'需求量',width:100,align:'center'},
//			{field:'parent',title:'计量单位',width:100,align:'center'}
	    ]],
	    fit:true,
		toolbar:[{
			iconCls: 'icon-edit',
			text:"编辑",
			handler:function(){
				
			}
		}
		,{
			iconCls: 'icon-add',
			text:"添加",
			handler:function(){
				
			}
		},{
			iconCls: 'icon-search',
			text:"查询",
			handler:function(){
			}
		}
		
		],
		onLoadSuccess:function(){//数据加载完毕之后触发事件..,想让数据端某列作为js按钮,就需要加载完数据后,给该列赋予easyui的类属性
			$("#btn_1").linkbutton({    
			    iconCls: 'icon-add'   
			});  
		},
		loadMsg:"亲，正在努力加载...，请耐心等候哦!!",
		singleSelect:true,
		fitColumns:true,
		pagination:true,
		rownumbers:true,
		onClickRow:function(rowIndex, rowData){
//							alert(rowIndex);
			alert(rowData.code_number);
		}
	})
}
function addtable(node){
	var flag = $('#center-tabs').tabs('getTab',node.text);
	var text = node.text
	var params = {text:text};
	var content = '<table id="tb" ></table>';
	if(flag==null){
		$('#center-tabs').tabs('add',{    
		    title:node.text,    
		    href:"href/machinetress.html",
//		    content:longcontent,
		    closable:true,
		    onLoad:function(panel){
		    	/******************************************/
//		    	var atab = $('#center-tabs').tabs('getSelected');
//		    	alert(atab.text);
		    	
		    	newTab(text,params);
		    		
		    	/******************************************/
		    }
		});
	}else{
//		window.parent.$('#center-tabs').tabs('close','J160-Bom');
		$('#center-tabs').tabs('select',node.text);
	}
}

//后台传过来的json
$('#tt1').tree({    
    url:'href/tree-structure/tree_data1.json',
    method:'get',
    animate:true,
    dnd:true,
    onClick: function(node){
    	addTab(node);
	}
})
$('#tt2').tree({    
    url:'href/tree-structure/tree_data2.json',
    method:'get',
    animate:true,
    dnd:true,
    onClick: function(node){
    	addTab(node);
	}
})
$('#tt3').tree({    
    url:'href/tree-structure/tree_data3.json',
    method:'get',
    animate:true,
    dnd:true,
    onClick: function(node){
    	addTab(node);
	}
})
$('#tt4').tree({    
    url:'href/tree-structure/tree_data4.json',
    method:'get',
    animate:true,
    dnd:true,
    onClick: function(node){
    	addTab(node);
	}
})
$('#tt5').tree({    
    url:'href/tree-structure/tree_data5.json',
    method:'get',
    animate:true,
//	lines:true,
    dnd:true,
    onClick: function(node){
    	addtable(node);
	}
})
